package com.cachopoid.utils;

import java.util.ArrayList;

import UtilsImagen.ImageLoader;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cachopoid.R;
import com.cachopoid.vo.EventoVO;

public class GridViewAdapter extends ArrayAdapter<EventoVO> {

	Context context; 
	int layoutResourceId; 
	ArrayList<EventoVO> data = new ArrayList<EventoVO>(); 
	
	public GridViewAdapter(Context context, int layoutResourceId, ArrayList<EventoVO> data) { 
		super(context, layoutResourceId, data); 
		this.layoutResourceId = layoutResourceId; 
		this.context = context; 
		this.data = data; 
	} 
	
	@Override public View getView(int position, View convertView, ViewGroup parent) { 
		View row = convertView; RecordHolder holder = null; 
		
		if (row == null) { 
			LayoutInflater inflater = ((Activity) context).getLayoutInflater(); 
			row = inflater.inflate(R.layout.template_row_grid, parent, false); 
			holder = new RecordHolder(); 
			holder.txtIdEvento = (TextView) row.findViewById(R.id.item_id);
			holder.txtDescripcion = (TextView) row.findViewById(R.id.item_text); 
			holder.txtTipoEvento = (TextView) row.findViewById(R.id.item_tipopevento); 
			holder.imageItem = (ImageView) row.findViewById(R.id.item_image); 
			row.setTag(holder); 
		} 
		else { 
			holder = (RecordHolder) row.getTag(); 
		} 
		EventoVO item = data.get(position); 
		holder.txtIdEvento.setText(item.getIdEvento().toString()); 
		holder.txtTipoEvento.setText(item.getTipoEvento());
		if(item.getTipoEvento().equals("I") && item.getIdCachopo()==0){
			holder.imageItem.setImageDrawable(context.getResources().getDrawable(R.drawable.evento_verde));
		}
		else{
			if(item.getTipoEvento().equals("I") && item.getIdEstablecimiento()==null){
				
				holder.imageItem.setImageDrawable(context.getResources().getDrawable(R.drawable.evento_rojo));
			}
			else{
				//inf = "Insertado nuevo Evento: ";
				//inf = context.getResources().getString(R.string.insertando_evento);
			}
			
		}
		holder.txtDescripcion.setText(item.getDescripcion());
		return row; 
	} 
	static class RecordHolder { 
		TextView txtIdEvento;
		TextView txtDescripcion;
		TextView txtTipoEvento;
		ImageView imageItem; 
	}

}
